/**
 * @ author: 汪孟苹
 */
define(['jquery','bbcare'],function($,$bb){
	var servers = {};
	var URL = $bb.baseUrl("followapp");

	/**
	 * 请求备孕妈妈BMI值
	 */
	servers.ajaxPrepregnancyBmi = function(params,callback){
		$bb.ajax({
			url: URL + "webapi/service/WctPrepregnancyBmi/qryPrepregnancyBmiByCondition",
			data:JSON.stringify({
				data : {
					"userId":params.info.userId, //"14G6xlFv60wrXJPqMiI8",
					"rows":params.rows,
					"page":params.page,
				}
			}),
			success: function(data){
				if(data.success){
					callback(data.data,params);
				}else{
					$bb.toastShow(data.msg ? data.msg : "查询备孕妈妈BMI值记录出错！");
				}
			}
		});
	}

	/**
	 * 孕前 处理备孕妈妈bmi值
	 */
	servers.hanleBmiData = function(list){
		for (var i = 0; i < list.length; i++) {
			if( list[i].bmi ){
				if( list[i].bmi < 18.5 ){
					list[i].weightSituation = "低体重";
					list[i].className= "text-green";
				}else if( list[i].bmi < 24.9 ){
					list[i].weightSituation = "标准体重";
				}else if( list[i].bmi < 29.9 ){
					list[i].weightSituation = "超重";
					list[i].className= "text-orange";
				}else{
					list[i].weightSituation = "肥胖";
					list[i].className= "text-red";
				}
			}
		}
		return {"list":list};
	}

	/**
	 * 孕前 请求月经与体温数据
	 */
	servers.ajaxPrepregnancyList = function(params,callback){
		$bb.ajax({
			url: URL + "webapi/service/qryPrepregnancyList",
			data:JSON.stringify({
				data : {
					"userId":params.info.userId,
					"queueId":params.info.queueId,
					"year":params.year,
				}
			}),
			success: function(data){
				if(data.success){
					callback(data.data,params);
				}else{
					$bb.toastShow(data.msg ? data.msg : "查询备孕妈妈月经与体温记录出错！");
				}
			}
		});
	}

	/**
	 * 将答案赋值给对应的天
	 */
	var dayArrSetValue = function(obj,arr){
		if( obj.day == "1" ) arr[0] = obj;
		if( obj.day == "2" ) arr[1] = obj;
		if( obj.day == "3" ) arr[2] = obj;
		if( obj.day == "4" ) arr[3] = obj;
		if( obj.day == "5" ) arr[4] = obj;
		if( obj.day == "6" ) arr[5] = obj;
		if( obj.day == "7" ) arr[6] = obj;
		if( obj.day == "8" ) arr[7] = obj;
		if( obj.day == "9" ) arr[8] = obj;
		if( obj.day == "10" ) arr[9] = obj;
		if( obj.day == "11" ) arr[10] = obj;
		if( obj.day == "12" ) arr[11] = obj;
		if( obj.day == "13" ) arr[12] = obj;
		if( obj.day == "14" ) arr[13] = obj;
		if( obj.day == "15" ) arr[14] = obj;
		if( obj.day == "16" ) arr[15] = obj;
		if( obj.day == "17" ) arr[16] = obj;
		if( obj.day == "18" ) arr[17] = obj;
		if( obj.day == "19" ) arr[18] = obj;
		if( obj.day == "20" ) arr[19] = obj;
		if( obj.day == "21" ) arr[20] = obj;
		if( obj.day == "22" ) arr[21] = obj;
		if( obj.day == "23" ) arr[22] = obj;
		if( obj.day == "24" ) arr[23] = obj;
		if( obj.day == "25" ) arr[24] = obj;
		if( obj.day == "26" ) arr[25] = obj;
		if( obj.day == "27" ) arr[26] = obj;
		if( obj.day == "28" ) arr[27] = obj;
		if( obj.day == "29" ) arr[28] = obj;
		if( obj.day == "30" ) arr[29] = obj;
		if( obj.day == "31" ) arr[30] = obj;
	}

	/**
	 * 获取prepregnancyList
	 */
	var getPrepregnancyList = function(obj){
		var arr = new Array(31);
		for (var i = 0; i < obj.prepregnancyList.length; i++) {
			dayArrSetValue(obj.prepregnancyList[i],arr);
		}
		for (var i = 0; i < arr.length; i++) {
			var obj1 = { 
				"day":(i+1).toString(),
			};
			if( !arr[i] ) arr[i] = obj1; 
		}
		obj.prepregnancyList = arr;
		return obj;
	}

	/**
	 * 将答案赋值给对应的月份
	 */
	var monthArrSetValue = function(obj,arr){
		if( obj.month == "1" ) arr[0] = getPrepregnancyList(obj);
		if( obj.month == "2" ) arr[1] = getPrepregnancyList(obj);
		if( obj.month == "3" ) arr[2] = getPrepregnancyList(obj);
		if( obj.month == "4" ) arr[3] = getPrepregnancyList(obj);
		if( obj.month == "5" ) arr[4] = getPrepregnancyList(obj);
		if( obj.month == "6" ) arr[5] = getPrepregnancyList(obj);
		if( obj.month == "7" ) arr[6] = getPrepregnancyList(obj);
		if( obj.month == "8" ) arr[7] = getPrepregnancyList(obj);
		if( obj.month == "9" ) arr[8] = getPrepregnancyList(obj);
		if( obj.month == "10" ) arr[9] = getPrepregnancyList(obj);
		if( obj.month == "11" ) arr[10] = getPrepregnancyList(obj);
		if( obj.month == "12" ) arr[11] = getPrepregnancyList(obj);
	}

	/**
	 * 填充
	 */
	var fill = function(){
		var arr = new Array(31);
		for (var i = 0; i < arr.length; i++) {
			arr[i] = {},
			arr[i].day = (i+1).toString()
		}
		return arr;
	}

	/**
	 * 创建数组day
	 */
	var dayArr = function(){
		var arr = new Array(31);
		for (var i = 0; i < arr.length; i++) {
			arr[i] = (i+1).toString();
		}
		return arr;
	}

	/**
	 * 孕前 处理月经与体温数据
	 */
	servers.handleMtData = function(list){
		var arr = new Array(12);
		for (var i = 0; i < list.length; i++) {
			monthArrSetValue(list[i],arr);
		}
		for (var i = 0; i < arr.length; i++) {
			var obj = { 
				"month":(i+1).toString(),
				"prepregnancyList":fill()
			};
			if( !arr[i] ) arr[i] = obj; 
		}
		return {
			"list":arr,
			"days":dayArr()
		};
	}

	return servers;
});